package me.firstapp.bbs.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import me.firstapp.bbs.base.BaseController;
import me.firstapp.common.json.SingleObject;
import me.firstapp.common.module.bbs.JsonPointAccount;
import me.firstapp.common.utils.ResponseUtils;
import me.firstapp.spi.shop.PointService;

@Controller
@RequestMapping("/point")
public class PointController extends BaseController {

	@Autowired
	private PointService pointService;

	@RequestMapping(value = "/pointRecharge")
	public ModelAndView pointRechargeView(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		Long memberId = getCurrentLoginMemberId(request, response);
		SingleObject<JsonPointAccount> result = pointService.findPointAccount(memberId);
		modelMap.put("pointAccount", result.getObject());
		return new ModelAndView("shop/pointRecharge", modelMap);
	}

	@RequestMapping(value = "/pointRecharge.do")
	public void recharge(String cardNo, String password, String payPassword, String code, HttpServletRequest request,
			HttpServletResponse response) {
		Long memberId = getCurrentLoginMemberId(request, response);
		SingleObject<JsonPointAccount> result = pointService.rechargePoint(memberId, cardNo, password, payPassword,
				code);
		ResponseUtils.renderJson(response, result);
	}
}
